#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/wait.h>
//#define NUM 10
const char* myfile = "/home/lsl/linux-code-notes/lesson19进程控制/code";
int main()
{
    char* const _env[] = {(char*)"MY_105_AV=312312112412"};
    pid_t id = fork();
    if(id == 0)
    {
        //child
        printf("子进程开始运行 pid::%d\n",getpid());
        sleep(2);
       // execl("/usr/bin/ls","ls","-l","-a",NULL);
        //execl(myfile, "code","-a",NULL);
       // execl("./code", "code","-a",NULL);
       char* const argv_[] = {(char*)"ls",(char*)"-a",(char*)"-i",(char*)"-l",NULL};
    // execv("/usr/bin/ls",argv_);
    // execvp("ls",argv_);
    //execle("./code","code","-a",NULL);
    execle("./code","code","-a",NULL,_env);
    //    execlp("ls","ls","-a","-l",NULL);
        exit(-1);//失败
    }
    else{
    
        //father
        printf("父进程开始运行 pid::%d\n",getpid());
        int status = 0;
        int ret = waitpid(-1, &status, 0);//阻塞等待
        if(ret > 0)
        {
            printf("wait susse  exit cod::%d\n",WEXITSTATUS(status));
        }

    }
    return 0;
}
